﻿using System.Collections.ObjectModel;
using System.ComponentModel;
using System;

namespace VisualStudioAchievements
{
    public class BindingPoint : INotifyPropertyChanged
    {
        static BindingPoint instance = null;
        static readonly object padlock = new object();

        public BindingPoint()
        {
        }

        public static BindingPoint Instance
        {
            get
            {
                lock (padlock)
                {
                    if (instance == null)
                    {
                        instance = new BindingPoint();
                    }
                    return instance;
                }
            }
        }
        //Used for the PerformanceProgressBar element that is bound to it, to represent
        //whether the NinerReader request failed or not.
        private bool _hidePerfBar;
        public bool HidePerfBar
        {
            get
            {
                return _hidePerfBar;
            }
            set
            {
                if (_hidePerfBar != value)
                {
                    _hidePerfBar = value;
                    NotifyPropertyChanged("HidePerfBar");
                }
            }
        }

        // The build identifier.
        public string BuildID 
        {
            get
            {
                return "1.0.0 (01272012)";
            }
        }

        public ObservableCollection<Niner> Niners { get; set; }

        private Niner _currentNiner;
        public Niner CurrentNiner
        {
            get
            {
                return _currentNiner;
            }
            set
            {
                if (_currentNiner != value)
                {
                    _currentNiner = value;
                    NotifyPropertyChanged("CurrentNiner");
                }
            }
        }

        private CompareNinerPair _comparedNiners;
        public CompareNinerPair ComparedNiners { 
            get
            {
                return _comparedNiners;
            }
            set
            {
                if (_comparedNiners != value)
                {
                    _comparedNiners = value;
                    NotifyPropertyChanged("ComparedNiners");
                }
            }
        }

        public ObservableCollection<CompareAchievementPair> ComparedAchievements { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                App.MainPageDispatcher.BeginInvoke(() => { PropertyChanged(this, new PropertyChangedEventArgs(info));});
            }
        }
    }
}
